package com.leaf.u_spring.chapter06;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
//import org.thymeleaf.spring4.SpringTemplateEngine;


@Configuration
public class ViewConfig {
	
	/**
	 * 配置Thymeleaf视图解析器
	 * @return
	 */
//	@Bean
//	public ViewResolver viewResolver_2(SpringTemplateEngine templateEngine){
//		ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
//		viewResolver.setTemplateEngine(templateEngine);
//		return viewResolver;
//	}
	
	/**
	 * 模板引擎
	 * @param templateResolver
	 * @return
	 */
//	@Bean
//	public TemplateEngine templateEngine(TemplateResolver templateResolver){
//		SpringTemplateEngine templateEngine = new SpringTemplateEngine();
//		templateEngine.setTemplateResolver(templateResolver);
//		return templateEngine;
//	}
	
	/**
	 * 模板解释器
	 * @return
	 */
//	@Bean
//	public TemplateResolver templateResolver(){
//		TemplateResolver templateResolver = new ServletContextTemplateResolver();
//		templateResolver.setPrefix("/WEB-INF/template/");
//		templateResolver.setSuffix(".html");
//		templateResolver.setTemplateMode("HTML5");
//		return templateResolver;
//	}
	
	
	/**
	 * 配置Tiles视图解析器
	 * @return
	 */
	@Bean
	public TilesConfigurer tilesConfigurer(){
		TilesConfigurer tiles = new TilesConfigurer();
		//指定tile定义的位置
		tiles.setDefinitions(new String[]{
				"/WEB-INF/layout/tiles.xml"
		});
		//启用刷新功能
		tiles.setCheckRefresh(true);
		return tiles;
	}
	
	@Bean
	public ViewResolver viewResolver_1(){
		return new TilesViewResolver();
	}
	
	/**
	 * 配置jsp视图解析器
	 * @return
	 */
	@Bean
	public ViewResolver viewResolver_0(){
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		
		resolver.setPrefix("/WEB-INF/views/");
		resolver.setSuffix(".jsp");
		
		//配置解析成JstlView
		resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class);
		
		return resolver;
	}

}
